﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using A2DFramework.EventService.Configuration;

namespace A2DFramework.EventService
{
    public class EventBusCoordinator
    {
        private EventBusCoordinator()
        {
            LoadEventBusProvider();
        }
        private static EventBusCoordinator _coordinator=null;
        public static EventBusCoordinator Instance() 
        {
            if (_coordinator==null)
                _coordinator = new EventBusCoordinator();
            return _coordinator;
        }

        private void LoadEventBusProvider()
        {
            if (EventServiceConfiguration.EventServer.Enabled)
                this.EventBus = new DistributeEventBus.DistributeEventBusProvider();
            else
                this.EventBus = new LocalEventBus.LocalEventBusProvider();
        }
        private IEventBusProvider EventBus { get; set; }

        public void Publish(IEventBase evt)
        {
            this.EventBus.Emit(evt);
        }

        public void Publish<T>(T evt)
            where T : IEventBase
        {
            this.EventBus.Emit(evt);
        }
    }
}
